<template>
  <DefaultFormListComponent :menuVo="menu"/>
</template>

<script setup>
import {useRoute, useRouter} from 'vue-router';
import {nextTick, onMounted, ref, shallowRef} from 'vue';
import {isEmpty} from '@/utils/CommonUtils';
import FormListViewHelper from '@/views/platwork/FormListView/FormListViewHelper';
import {DefaultAppMenu, DefaultFormDefinition, DefaultMenuDefinition} from '@/components/form/DefaultFormDefinition';
import DefaultFormListComponent from '@/components/platwork/DefaultFormListComponent';

defineOptions({
  name: 'FormListView',
})

const route = useRoute();
const helper = shallowRef();
const loading = shallowRef(false);
const menu = shallowRef({
  appMenu: JSON.parse(JSON.stringify(DefaultAppMenu)),
  formMenu: JSON.parse(JSON.stringify(DefaultMenuDefinition)),
  formDefinition: JSON.parse(JSON.stringify(DefaultFormDefinition))
});

onMounted(() => {
  let menuId = route.query.menuId;
  if (isEmpty(menuId)) return;
  helper.value = new FormListViewHelper({menuId, loading});
  helper.value.loadMenuById().then(menu => {
    setFormMenu(menu);
  });
});

function setFormMenu(menuVo) {
  nextTick(() => {
    menu.value = menuVo;
  });
}
</script>
